#ifndef IOMANAGER_H
#define IOMANAGER_H

#include <QtCore>
#include "commons.h"

class IOManager
{
public:
    IOManager(const QString& fileName);
//    void saveLevel(const Level* const level);
    void saveLevels(const QLinkedList<Level*>& levels);
    Level* loadLevel(qint32 id);
    void loadLevels(QLinkedList<Level*>& levels);

private:
    void openLevelFile();
    void closeLevelFile();
    void encryptData();
    void decryptData();
    void charToByte(char* chars, byte* bytes, unsigned int count);
    void byteToChar(byte* bytes, char* chars, unsigned int count);
    void encryptBlock(byte* plaintext, byte* ciphertext, unsigned int count);
    void decryptBlock(byte* ciphertext, byte* plaintext, unsigned int count);
    void privateLoadLevels(QLinkedList<Level*>& levels);
    QString fileName;
    QFile* levelsFile;
    QByteArray data;
    byte* byteKey;
};

#endif // IOMANAGER_H
